package com.micaelvesterlund.skeerkie.shared.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Game {
	private LineUp homeLineUp;
	private LineUp awayLineUp;
	private Date date;
	private List<Score> scores = new ArrayList<Score>();
	private FinalScore finalScore;

	public Game(LineUp homeTeam, LineUp awayTeam) {
		this.homeLineUp = homeTeam;
		this.awayLineUp = awayTeam;
	}

	public void addScore(Score score) {
		scores.add(score);
	}

	public FinalScore getFinalScore() {
		return finalScore;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Date getDate() {
		return date;
	}

	public List<Score> getScores() {
		return scores;
	}

	public void setScores(List<Score> scores) {
		this.scores = scores;
	}

	public LineUp getHomeLineUp() {
		return homeLineUp;
	}

	public LineUp getAwayLineUp() {
		return awayLineUp;
	}

	public void start() {
		setDate(new Date());
	}

	public void end() {
		int home = 0;
		int away = 0;
		for (Score score : scores) {
			if (score.getTeam().equals(homeLineUp.getTeam())) {
				home++;
			} else {
				away++;
			}
		}
		finalScore = new FinalScore(home, away);
	}

}
